/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vs.kindlecoll.UI;

import com.vs.kindlecoll.Beans.Book;
import com.vs.kindlecoll.Beans.BooksCollection;
import com.vs.kindlecoll.IO.KindleInteractor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTree;

/**
 *
 * @author volodymyr.sadovyy
 */
class PopupMenu extends JPopupMenu implements ActionListener {

    JMenuItem delItem;
    JMenuItem addCollectionItem;
    JMenuItem showProperties;

    public PopupMenu() {
        delItem = new JMenuItem("Delete");
        delItem.addActionListener(this);
        add(delItem);

        addCollectionItem = new JMenuItem("Create new collection");
        addCollectionItem.addActionListener(this);
        add(addCollectionItem);

        showProperties = new JMenuItem("Properties");
        showProperties.addActionListener(this);
        add(showProperties);

    }

    public void actionPerformed(ActionEvent e) {
        UIHelper uiHelp = new UIHelper();
        //---------------DELETE-------------------------------------------------
        if (e.getActionCommand().equalsIgnoreCase("Delete")) {
            if (this.getInvoker().getClass().equals(JTree.class)) {
                uiHelp.delCollectionElement((JTree) this.getInvoker());
            } else if (this.getInvoker().getClass().equals(JList.class)) {
                uiHelp.delBookElement((JList) this.getInvoker());
            }
                //---------------CREATE NEW COLLECTION----------------------------------
            } else if (e.getActionCommand().equalsIgnoreCase("Create new collection")) {
                KindleInteractor.createCollection();
                uiHelp.updateTreeModel(((JTree) this.getInvoker()));
            } //---------------SHOW PROPERTIES----------------------------------
            else if (e.getActionCommand().equalsIgnoreCase("Properties")) {
                uiHelp.showBookProperties(this.getInvoker());
            }
        }


    
}